*****************************************************************************************
* Project: Crisis Management and Attitudes towards Democracy (European Union Politics)  *
* Date: 04 February 2025                                                                *
* Authors:  Lea Heyne & Rubén Ruiz-Rufino                                               *
* Do-file 1: Main analysis and descriptive graphs                                       *
* Data: Eurobaromenter EB93.1                                                           *
*****************************************************************************************

/*
_________________________________________________________________________________________________________________________________________________________
Notes on this dofile
_________________________________________________________________________________________________________________________________________________________
This part of the analysis exploits the timing of the EB93.1 to conduct a quasi-experiment using the 
adoption of the Recovery and Resilience Fund on 21 July 2020 as an unexpected event. We also produce
descriptive graphs regarding data distribution and salience. 

Note on data: EB93.1 comes from file ZA7649_v2-0-0.dta which can be dowlowaded at:
https://www.gesis.org/en/eurobarometer-data-service/data-and-documentation/standard-special-eb/study-overview/eurobarometer-931-za7649-july-august-2020
_________________________________________________________________________________________________________________________________________________________
*/
clear all

*Macros
global root    "C:\pathway"
global figures "$root\figures\"
global tables  "$root\tables\"
global data    "$root\data\" 
                                                                  
use "$data\eb93.1.dta", clear

*Unify West and East Germany
replace country=4 if country==14

*Country-level variables
g emu=0
replace emu=1 if country==1 | country==2  | country==3 | country==4 | country==5 | country==6 | country==8 | country==11 | country==12 | country==13 | country==16 | country==18
label define EMU 1 "France" 2 "Belgium" 3 "Netherlands" 4 "Germany" 5 "Italy" 6 "Luxembourg" 8 " Ireland" 11 "Greece" 12 "Spain" 13 "Portugal" 16 "Finland" 18 "Austria" 
label value country EMU

keep if emu==1

g bailout=country==8 | country==11 | country==12 | country==13 | country==5
lab var bailout "Bailout"

*DV - SWD
rename sd18a swd
replace swd=. if swd==5
label var swd "Satisfaction with democracy"
recode swd (1/2=1 "Satisfied")(3/4=0 "Not satisfied")(else=.),into(swd_bi)


*Clean other relevant variables

gen year=.
replace year=2020 if year==.
rename w11 weight
lab var weight "Euro 15"

rename d11 age
lab var age "Age"
rename d8r1 education
lab var education "Education (years)"
recode education (97/98=.)(11=0)
rename d10 gender
lab var gender "Gender (female)"
rename d15a occupation 
gen paidjob = 1
replace paidjob = 0 if occupation == 1 | occupation == 2 | occupation == 3 | occupation == 4 
label var paidjob "In a paid job"
gen housework = 0
replace housework = 1 if occupation == 1
label var housework "Housework"
gen student = 0
replace student = 1 if occupation == 2
label var student "Student"
gen unemployed = 0
replace unemployed = 1 if occupation == 3
label var unemployed "Unemployed" 
gen retired = 0
replace retired = 1 if occupation == 4
label var retired "Retired"
rename capi_cawi CAPI
label var CAPI "Interview: CAPI"
rename p5 cooperation
label var cooperation "Respondent cooperation (low)"


*Treatment - Date variable
rename p1 date

/* Generating the different treatment/control variables used throughout the paper: 
- naive --> All respondents
Those interviewed on the day of the announcement (July 21) are excluded from all the analyses (see Munoz et al).  
*/ 

* Naive 
gen treatment = . 
replace treatment= 0 if date < 17
replace treatment = 1 if date > 17
tab date treatment, m
label var treatment "NextGenEU"

g interaction=treatment*bailout
lab var interaction "NextGenEUXBailout"

* code respondent age 

gen age2 = 0 
replace age2 = 1 if age >= 26
gen age3 = 0 
replace age3 = 1 if age >= 28

*date variable where 1st day of fieldwork is 0 in each country

bys country: egen mindate=min(date)
g datenum=date-mindate
sum treatment datenum if treatment!=.

***********************
* Table 1: Testing H1 *
***********************

estimates clear
preserve
eststo m1: reg swd_bi treatment, vce(robust)            
estadd local sample "EMU"
estadd local treatment "RRF"
estadd local time "No"
estadd local FE "No"
estadd local SE "Yes"

eststo m2: reg swd_bi treatment datenum , vce(robust)            
estadd local sample "EMU"
estadd local treatment "RRF"
estadd local time "Yes"
estadd local FE "No"
estadd local SE "Yes"

eststo m3: reg swd_bi treatment datenum i.country , vce(robust)            
estadd local sample "EMU"
estadd local treatment "RRF"
estadd local time "Yes"
estadd local FE "Yes"
estadd local SE "Yes"

eststo m4: reg swd_bi treatment datenum if country!=5, vce(robust)           
estadd local sample "EMU-No ITA"
estadd local treatment "RRF"
estadd local time "Yes"
estadd local FE "No"
estadd local SE "Yes"

esttab m1 m2 m3 using "$tables/EMUCrisesDemocracy_Table_experiment_H1.tex", replace booktabs compress label ///
keep(_cons treatment) star(+ 0.10 * 0.05 ** 0.01 *** 0.001)  ///
mtitles("Baseline" "Timing" "FE") s(N sample treatment time FE SE, label("Obs." "Sample" "Treatment" "Temporal effects" "Country-level FE" "Robust SE" ))
restore

***********************
* Table 2: Testing H2 *
***********************

estimates clear
preserve
eststo m1: reg swd_bi interaction treatment bailout datenum if country!=5, vce(robust)   
estadd local sample "EMU-No ITA"
estadd local treatment "RRF"
estadd local time "Yes"
estadd local SE "Yes"
estadd local age "All"
eststo m2: reg swd_bi interaction treatment bailout datenum, vce(robust)  
estadd local sample "EMU-ITA"
estadd local SE "Yes"
estadd local treatment "RRF"
estadd local age "All"
estadd local time "Yes"
eststo m3:reg swd_bi interaction treatment bailout datenum if age3 == 0 & country!=5, vce(robust) 
estadd local sample "EMU-No ITA"
estadd local SE "Yes"
estadd local treatment "RRF"
estadd local age "-18 in 2010"
estadd local time "Yes"
eststo m4:reg swd_bi interaction treatment bailout datenum if age3 == 1 & country!=5, vce(robust) 
estadd local sample "EMU-No ITA"
estadd local SE "Yes"
estadd local treatment "RRF"
estadd local age "18+ in 2010"
estadd local time "Yes"
esttab m1 m3 m4 m2 using "$tables/EMUCrisesDemocracy_Table_experiment_H2.tex", replace booktabs compress label ///
keep(_cons treatment bailout interaction) star(+ 0.10 * 0.05 ** 0.01 *** 0.001)  ///
mtitles("Baseline""No bailout experience" "Bailout experience" "Italy" ) s(N sample treatment time SE age, label("Obs." "Sample" "Treatment" "Temporal effects" "Robust SE" "Age" ))
restore


*****************************************************************************
* Figure 1: Distribution of observations over survey fieldwork              *
*****************************************************************************

ssc install stripplot, replace 
ssc install blindschemes, replace 

set scheme plottigblind

* Generating time running variable where 0 corresponds to the day after the announcement (July 21)

gen time_zero = date - 17 

replace time_zero = . if date == 17

replace time_zero = time_zero - 1 if time_zero > 0

label var time_zero "Days"

bysort time_zero country: egen avgsatisfaction = mean(swd_bi)
bysort country time_zero: egen avgsatisfaction2 = mean(swd_bi)

stripplot time_zero, by(country) stack xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ms(oh) msize(small) 

graph save "$figures\Figure_Days.gph", replace 
graph export "$figures\Figure_Days.pdf", as(pdf) replace 

* Country dummies 
tab country, gen(country_)

label var country_1 "France"
label var country_2 "Belgium"
label var country_3 "Netherlands"
label var country_4 "Germany"
label var country_5 "Italy"
label var country_6 "Luxembourg"
label var country_7 "Ireland"
label var country_8 "Greece"
label var country_9 "Spain"
label var country_10 "Portugal"
label var country_11 "Finland"
label var country_12 "Austria"

graph twoway scatter avgsatisfaction time_zero if country_1 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("France") saving(1, replace) 
graph twoway scatter avgsatisfaction time_zero if country_2 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("Belgium") saving(2, replace)
graph twoway scatter avgsatisfaction time_zero if country_3 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("Netherlands") saving(3, replace )
graph twoway scatter avgsatisfaction time_zero if country_4 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("Germany") saving(4, replace)
graph twoway scatter avgsatisfaction time_zero if country_5 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("Italy") saving(5, replace)
graph twoway scatter avgsatisfaction time_zero if country_6 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("Luxembourg") saving(6, replace)
graph twoway scatter avgsatisfaction time_zero if country_7 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("Ireland") saving(7, replace)
graph twoway scatter avgsatisfaction time_zero if country_8 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("Greece") saving(8, replace)
graph twoway scatter avgsatisfaction time_zero if country_9 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("Spain") saving(9, replace)
graph twoway scatter avgsatisfaction time_zero if country_10 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("Portugal") saving(10, replace)
graph twoway scatter avgsatisfaction time_zero if country_11 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("Finland") saving(11, replace)
graph twoway scatter avgsatisfaction time_zero if country_12 == 1, xtitle("Days") xline(0, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) ytitle("Satisfaction with democracy") title("Austria") saving(12, replace)

graph combine 1.gph 2.gph 3.gph 4.gph 5.gph 6.gph 7.gph 8.gph 9.gph 10.gph 11.gph 12.gph

graph save "$figures\Figure_SWD.gph", replace 
graph export "$figures\Figure_SWD.pdf", as(pdf) replace 


*****************************************************************************
* Figure 2: Media mentions for key search terms during the survey fieldwork *
*****************************************************************************

use "$data\media.dta", clear

graph twoway	(line media_mentions date, ///
				xline(22117, lpattern(tight_dot) lwidth(medthick) lcolor(greyscale1)) xlabel(22097 22111 22127 22142 22158, format("%td")  angle(forty_five)) ///
				xtitle("") ytitle("Number of newspaper articles") ti("Media coverage")) 
				
graph save "$figures\media.gph", replace 
graph export "$figures\media.pdf", as(pdf) replace 

